<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">


<ui:composition template="/WEB-INF/templates/maintemplate.xhtml">
	<ui:define name="metadata">
		<f:metadata>
			<f:viewParam name="navCatId" value="${flash.keep.navCatId}" requiredMessage="No Category Selected">
				<f:validateRequired disabled="#{ !empty flash.navCatId}"></f:validateRequired>
			</f:viewParam>
		</f:metadata>
	</ui:define>
	<ui:define name="navigation">
		<f:event type="preRenderComponent" listener="#{navigationMapBackingBean.clearNavigationMapNewsCategory()}" />
		<ui:include src="/navigationNews.xhtml"></ui:include>
	</ui:define>

	<ui:define name="content">
		<f:event type="preRenderComponent" listener="#{newsCategoryBackingBean.loadTopCategories}" />
		<h:form id="listCategoryForm">
			<p:dataTable id="categoryTable" value="#{newsCategoryBackingBean.lazyNewsCategoryDataModel}" var="category" paginator="true" rows="20"
				paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}  {PageLinks}  {CurrentPageReport} {NextPageLink} {LastPageLink}"
				paginatorPosition="bottom" tableStyleClass="noBorderTable" lazy="true">
				<p:column headerText="#{msgs.categoryName}">
					<h:link value="#{category.categoryName}" outcome="/news/listnews" rendered="#{empty category.childrenCategory}">
						<f:param name="#{constants.nameToValueMap.CATEGORY__NEWS_ID}" value="#{category.id}"></f:param>
					</h:link>
					<h:link value="#{category.categoryName}" outcome="/newscategory/listcategories" rendered="#{! empty category.childrenCategory}">
						<f:param name="#{constants.nameToValueMap.NAVIGATION_CATEGORY_ID}" value="#{category.id}"></f:param>
					</h:link>
				</p:column>
				<p:column headerText="#{msgs.categoryDescriptionLabel}">
					<h:outputText value='#{category.description}' escape="false"></h:outputText>
				</p:column>
				<p:column headerText="#{msgs.CategoryOwner}">
					<h:outputText value='#{category.categoryOwner.userId}' escape="false"></h:outputText>
				</p:column>
				<p:column headerText="#{msgs.NumberOfNews}">
					<h:outputText value='#{category.numOfNews}' escape="false"></h:outputText>
				</p:column>
				<p:column headerText="#{msgs.displayTypeOnNewsCategory}">
					<h:outputText value='#{category.displayType}' escape="false"></h:outputText>
				</p:column>
				<p:column headerText="#{msgs.displayTypeOnMainIndexPage}">
					<h:outputText value='#{category.displayTypeOnMainIndexPage}' escape="false"></h:outputText>
				</p:column>
				<p:column headerText="#{msgs.action}" rendered="#{login.userInSysadmin}">
					<h:panelGroup>
						<p:button value="#{msgs.EDIT}" outcome="editcategory">
							<f:param name="id" value="#{category.id}"></f:param>
						</p:button>

						<p:commandButton value="#{msgs.deleteButton}" actionListener="#{newsCategoryBackingBean.setNewsCategory(category)}" update=":delConfgDiaForm"
							process="@form" oncomplete="DelConfgDia.show()" styleClass="commandButtonOrLink" onerror="HandleAjaxError(xhr, satus, exception)">
						</p:commandButton>

						<p:commandButton value="#{msgs.assignOwner_button}" actionListener="#{newsCategoryBackingBean.setNewsCategory(category)}"
							update=":assignOwnerForm" process="@form" oncomplete="assignOwnerDia.show()" onerror="HandleAjaxError(xhr, satus, exception)">
						</p:commandButton>

						<p:commandButton value="#{msgs.displayTypeMainIndexRegular}"
							actionListener="#{newsCategoryBackingBean.changeDisplayTypeOnMainIndexPage(category,constants.nameToValueMap.Display_Type_Regular_Main_Index)}"
							update="@form" process="@form" onerror="HandleAjaxError(xhr, satus, exception)"
							rendered="#{!category.displayTypeOnMainIndexPage.toString().equals(constants.nameToValueMap.Display_Type_Regular_Main_Index)}">
						</p:commandButton>
						<p:commandButton value="#{msgs.displayTypeMainIndexMixed}"
							actionListener="#{newsCategoryBackingBean.changeDisplayTypeOnMainIndexPage(category,constants.nameToValueMap.Display_Type_Mixed_Main_Index)}"
							update="@form" process="@form" onerror="HandleAjaxError(xhr, satus, exception)"
							rendered="#{!category.displayTypeOnMainIndexPage.toString().equals(constants.nameToValueMap.Display_Type_Mixed_Main_Index)}">
						</p:commandButton>

					</h:panelGroup>

					<h:panelGroup rendered="#{empty category.childrenCategory}">
						<p:commandButton value="TabDisplayType"
							actionListener="#{newsCategoryBackingBean.changeDisplayType(category,constants.nameToValueMap.Display_Type_Tab)}" update="@form"
							process="@form" onerror="HandleAjaxError(xhr, satus, exception)"
							rendered="#{!category.displayType.toString().equals(constants.nameToValueMap.Display_Type_Tab)}">
						</p:commandButton>
						<p:commandButton value="RegularDisplayType"
							actionListener="#{newsCategoryBackingBean.changeDisplayType(category,constants.nameToValueMap.Display_Type_Regular)}" update="@form"
							process="@form" onerror="HandleAjaxError(xhr, satus, exception)"
							rendered="#{!category.displayType.toString().equals(constants.nameToValueMap.Display_Type_Regular)}">
						</p:commandButton>
					</h:panelGroup>
				</p:column>
			</p:dataTable>
		</h:form>

		<div style="display: inline; float: left; margin-top: 10px;">
			<p:button value="#{msgs.postNewCategory}" outcome="/newscategory/createcategory.xhtml" rendered="#{login.userInSysadmin}">
			</p:button>
		</div>

		<p:dialog id="confirmation" widgetVar="DelConfgDia" header="#{msgs.Delete_Dialog_Header} " modal="true" height="150" width="500">
			<h:form id="delConfgDiaForm">
				<h:panelGrid id="selectupdate">
					<h:outputFormat value="#{msgs.Category_Delete }">
						<f:param value="#{newsCategoryBackingBean.newsCategory.categoryName}">
						</f:param>
					</h:outputFormat>
					<!-- create some space between the label and the button -->
					<br></br>
					<br></br>
					<h:panelGrid columns="2">
						<p:commandButton id="confirm" value="#{msgs.Delete_Dialog_Yes}" update=":listCategoryForm" process="@this" oncomplete="DelConfgDia.hide()"
							actionListener="#{newsCategoryBackingBean.deleteCategory}" />
						<p:commandButton id="decline" value="#{msgs.Delete_Dialog_No}" onclick="DelConfgDia.hide()" type="button" />
					</h:panelGrid>

				</h:panelGrid>
			</h:form>
		</p:dialog>
		<p:dialog id="assignOwner" widgetVar="assignOwnerDia" header="#{msgs.Assign_Owner_Header}" modal="true" height="250" width="600">
			<h:form id="assignOwnerForm">
				<h:panelGrid columns="2" columnClasses="th">

					<h:outputLabel value="#{msgs.categoryName}"></h:outputLabel>
					<h:outputText value="#{newsCategoryBackingBean.newsCategory.categoryName}" />

					<h:outputLabel value="#{msgs.CurrentCategoryOwner}"></h:outputLabel>
					<h:outputText value="#{newsCategoryBackingBean.newsCategory.categoryOwner.userId}" />

					<h:outputLabel value="#{msgs.provideUserId}" for="userId" />
					<p:autoComplete value="#{requestScope.NEWUSERID}" minQueryLength="3" id="userId" completeMethod="${userBackingBean.getUserids}"
						forceSelection="false" queryDelay="500">
					</p:autoComplete>
					<p:message for="userId" />

					<h:panelGroup>
						<p:commandButton value="#{msgs.Assign_Button}" action="#{newsCategoryBackingBean.assignCategoryOwner()}" process="@form"
							update=":listCategoryForm" oncomplete="assignOwnerDia.hide()">
						</p:commandButton>
						<p:commandButton id="cancel" value="#{msgs.CANCEL}" onclick="assignOwnerDia.hide()" type="button" />
					</h:panelGroup>

				</h:panelGrid>
			</h:form>
		</p:dialog>
	</ui:define>
</ui:composition>

</html>